const { TaskQueue } = require('../task-queue')
const { log } = require('../util')

let task = (args) => {
    return new Promise((resovle, rejects) => {
        if (args == 6) {
            rejects()
        } else {
            setTimeout(() => {
                log.debug('args=' + args)
                resovle()
            }, 3000)
        }
    })
}

let queue = new TaskQueue('test queue', task)
let queue2 = new TaskQueue('test queue2', task)

console.log(queue.toString())
console.log(queue2.toString())

queue.push(1)
queue2.push(10)

setTimeout(() => {
    queue.push(5)
    queue.push(6)
    queue.push(7)

    queue2.push(17)
    queue2.push(27)

    console.log(queue.toString())
    console.log(queue2.toString())
}, 5000);

setTimeout(() => {
    console.log(queue.toString())
    console.log(queue2.toString())
}, 20000)